/**
 * @author harae Feng 
 * @date 2019-09-23 17:40:11 
 * @Last Modified by: harae Feng
 * @Last Modified time: 2019-09-23 18:34:59
 * @Describe 酷我歌手-MVURL
 */

const fetch = require('../../util/fetchUtil').fetchRequest
const ResultAPI = require('../../routes/api/resultAPI')
const CatchHandle = require('../../routes/api/apicatch')


/**
 * MVURL
 * @param {String} rid 
 * @param {Int} pn 
 * @param {Int} rn 
 */
async function urlMv(rid){
    let url = `http://www.kuwo.cn/url?format=mp4&rid=${rid}&response=url&type=convert_url3`
    let res = await fetch(url)
    let resJSON = await res.json()
    return resJSON
}

async function urlMvAPI(ctx){
    try {
        const rid = ctx.query.rid

        if(!artistid){return new ResultAPI(10000)}

        let resJSON = await urlMv(rid)
        if(resJSON.code === 200){
            return new ResultAPI(0, {}, resJSON.data)
        }else{
            return new ResultAPI(10003)
        }       
    } catch (error) {
        return CatchHandle(__dirname, __filename, error)
    }
}

module.exports = {
    urlMvAPI: urlMvAPI
}